

from math import sqrt
from bisect import bisect

def pgen():
    primes = [2]
    yield 2
    i = 3
    while True:
        is_prime = True
        for p in primes[:bisect(primes, int(sqrt(i)))]:
            if i % p == 0:
                is_prime = False
                break
        if is_prime:
            yield i
            primes.append(i)
        i += 2

class prime_tester():
    def __init__(self):
        self.__prime_gen = pgen()
        self.__primes = []
        for i in self.__prime_gen:
            self.__primes.append(i)
            break
    
    def __call__(self, n):
        if n <= 0:
            return False
        if n > self.__primes[-1]:
            for i in self.__prime_gen:
                self.__primes.append(i)
                if i >= n:
                    break
        return n in self.__primes

def euler_len(pt, a, b):
    n = 0
    while pt(n * n + a * n + b):
        n += 1
    return n

if __name__ == '__main__':
    pt = prime_tester()
    ma, mb = 1, 41
    max = euler_len(pt, ma, mb)
    print ma, mb, max
    for a in range(-999, 1000):
        for b in range(-999, 1000):
            el = euler_len(pt, a, b)
            if el > max:
                ma, mb, max = a, b, el
                print ma, mb, max